
import { HttpNoticeList, HttpReadNotice } from '../../../service/notice';
import TableList from "../../../components/templates/tablelist";
import mixin from '../mixin';
import compDetail from './detailmodal';

export default {
    mixins: [TableList, mixin],
    components: {
        compDetail
    },
    data() {
        return {
            isMixin: true,
            Tools: { show: true },
            Tabs: { show: true },
            formData: {
                search: {
                    EQ_notifyReadStatus: null
                }
            },
            Searchs: {
                show: true,
                labelWidth: 90,
            },
            Plugins: { show: true },
        };
    },
    methods: {
        ajaxRequest: HttpNoticeList,
        handleOperates(params, type, batch) {
            if (batch === true) {
                params = (params || this.checkedData.join(',')) + '';
                if (!params.length) return this.$Message.warning('请选择至少一条数据');
            }
            switch (type) {
                case 'query':
                    this.operate = {
                        show: true,
                        id: params,
                        title: "消息查看",
                        component: "compDetail",
                       	width: 'large',
                        showFooter: false
                    };
                    break;
                case 'mark':
                    this.operate = {
                        show: true,
                        alert: 'primary',
                        params: { ids: params },
                        title: '标记已读',
                        ajaxRequest: HttpReadNotice,
                    }
                    break;
                case 'markall':
                    this.operate = {
                        show: true,
                        alert: 'primary',
                        params: { ids: '' },
                        title: '全部标记为已读',
                        ajaxRequest: HttpReadNotice,
                    }
                    break;
            }
        },
    },
    computed: {
        ToolsData() {
            return [
                {
                    name: "标记已读",
                    operate: "mark",
                    theme: "primary",
                    batch: true,
                },
                {
                    name: "全部标记为已读",
                    operate: "markall",
                },
            ]
        },
        TabsData() {
            return [
                {
                    name: "全部",
                    key: 'EQ_notifyReadStatus',
                    val: null
                }, {
                    name: "新消息",
                    key: 'EQ_notifyReadStatus',
                    val: '0'
                }, {
                    name: "历史消息",
                    key: 'EQ_notifyReadStatus',
                    val: '1'
                }
            ]
        },
        SearchsData() {
            return [
                {
                    label: "内容",
                    key: 'CN_title',
                    tag: 'Input',
                    show: true,
                },
                {
                    label: "消息类型",
                    key: 'EQ_notifyType',
                    tag: 'Select',
                    show: true,
                    options: this.getNoticeTypes,
                },
            ]
        },
        columns() {
            return [
                {
                    type: 'selection',
                    width: 40,
                    align: 'center',
                    formName: 'id'
                },
                {
                    title: '#',
                    type: 'index',
                    width: 40,
                    align: 'center',
                },
                {
                    title: '标题',
                    key: 'title',
                    render: (h, { row }) => {
                        return <span class="color-link" onClick={this.handleOperates.bind(this, row.id, 'query')}>{row.title}</span>
                    },
                },
                {
                    title: '消息类型',
                    key: 'notifyType',
                    render: (h, { row }) => this.findRenderLabel(this.getNoticeTypes, row.notifyType),
                },
                {
                    title: '状态',
                    key: 'notifyReadStatus',
                    render: (h, { row }) => {
                        return row.notifyReadStatus == 0 ? <Tag color="error" type="border">未读</Tag> : <Tag color="confirm" type="border">已读</Tag>;
                    },
                },
                {
                    title: "平台单据编号",
                    key: "idLabel",
                },
                {
                    title: "来源单据编号",
                    key: "srcLabel",
                },
                {
                    title: '简述',
                    key: 'brief',
                    // render: (h, { row }) => {
                    //     return <div class={{ 'font-bold': row.notifyReadStatus == 0 }}>{row.brief}:{row.srcLabel}</div>
                    // },
                }, {
                    title: '日期',
                    key: 'notifyReceiveAt',
                }];
        },
    },
};




